package com.copa.l705;

import java.util.HashMap;

/**
 * @author copa
 * @createDate 2022-06-13 11:13
 * @function HashMap api
 */
public class Test2 {

    public static final Integer CONSTANTS = 1;

    private HashMap<Integer, Integer> map;

    public Test2() {
        this.map = new HashMap<>();
    }

    public void add(int key) {
        if (!map.containsKey(key)) {
            map.put(key, CONSTANTS);
        }
    }

    public void remove(int key) {
        if (map.containsKey(key)) {
            map.remove(key);
        }
    }

    public boolean contains(int key) {
        return map.containsKey(key) ? true : false;
    }

    public static void main(String[] args) {
        Test2 myHashSet = new Test2();
        myHashSet.add(1);      // set = [1]
        myHashSet.add(2);      // set = [1, 2]
        myHashSet.contains(1); // 返回 True
        myHashSet.contains(3); // 返回 False ，（未找到）
        myHashSet.add(2);      // set = [1, 2]
        myHashSet.contains(2); // 返回 True
        myHashSet.remove(2);   // set = [1]
        myHashSet.contains(2); // 返回 False ，（已移除）
    }
}
